﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxHiddenField;

namespace Project_Udrinkwater
{
    public partial class MenuSelectPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void hfCustomIntervals_Init(object sender, EventArgs e)
        {
            ASPxHiddenField hiddenField = sender as ASPxHiddenField;

            hiddenField["UD1"] = 2000;
            hiddenField["UD2"] = 5000;
            hiddenField["UD3"] = 1000;
            hiddenField["UD4"] = 4000;
        }

        protected void Bt_PageCustomer_Click(object sender, EventArgs e)
        {
            Response.Redirect("ShowOrder.aspx");
        }

        protected void btOKCustomer_Click(object sender, EventArgs e)
        {
            if (Membership.ValidateUser(tbLogin.Text, tbPassword.Text))
            {
                if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                {
                    FormsAuthentication.SetAuthCookie(tbLogin.Text, false);
                    Session["User"] = tbLogin.Text;
                    string[] user = Roles.GetRolesForUser(tbLogin.Text);
                    if (user[0] == "Admin")
                    {
                        Response.Redirect("~/Admin/Default.aspx");
                    }
                    if (user[0] == "Officer")
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                    if (user[0] == "Customer")
                    {
                        Response.Redirect("~/Customer/Order.aspx");
                    }
                }
                else
                    FormsAuthentication.RedirectFromLoginPage(tbLogin.Text, false);
            }
            else
            {
                //tbLogin.ErrorText = "Invalid user";
                //tbLogin.IsValid = false;
                Response.Write(@"<script language='javascript'>alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง')</script>");
            }
        }
    }
}